<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="kr.icg.icgmshtest1.PMF"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="kr.icg.icgmshtest1.Wish"%>
<%@page import="java.util.Date"%><%
String toNameFirst = request.getParameter("toNameFirst");
String toNameLast = request.getParameter("toNameLast");
int contentNumber = Integer.parseInt(request.getParameter("contentNumber"));
Date date = new Date();

Wish wish = new Wish(toNameFirst, toNameLast, contentNumber, date);

PersistenceManager pm = PMF.get().getPersistenceManager();
try {
	pm.makePersistent(wish);
} finally {
	pm.close();
}
%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.List"%>
<%@page import="kr.icg.icgmshtest1.BaramSelection"%><div id="registerdWish">
	<div class="toolbar">
		<h1>네게바라 등록결과</h1>
		<a href="#home" class="back">Home</a>
	</div>
	<h2>바람검색 결과</h2>
<%
PersistenceManager pm2 = PMF.get().getPersistenceManager();
String query = "select from " + Wish.class.getName() 
	+ " where toNameFirst == '" + request.getParameter("toNameFirst") 
	+ "' && toNameLast == '" + request.getParameter("toNameLast") 
	+ "' order by date desc";
List<Wish> wishes = (List<Wish>) pm2.newQuery(query).execute();
if (wishes.isEmpty()) {
%>
	<ul class="rounded">
		<li>No wishes!<%= request.getParameter("toNameFirst") %></li>
	</ul>
<%
} else {
	for (Wish w : wishes) {
%>
	<ul class="rounded">
		<li class="arrow">
			<a href="#">
				<small><%= new SimpleDateFormat("MM.dd").format(w.getDate()) %></small>
				<em>to.</em> <%= w.getToNameLast() %> <%= w.getToNameFirst() %>
			</a>
		</li>
		<li><%= BaramSelection.getBaramContent(w.getContentNumber()) %></li>
	</ul>
<%
	}
}
%>
</div>